# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=spice-gtk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.38
pkgrel=2
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="GTK3 widget for SPICE clients (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-cyrus-sasl"
         "${MINGW_PACKAGE_PREFIX}-dbus-glib"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
         "${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-lz4"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-phodav"
         "${MINGW_PACKAGE_PREFIX}-pixman"
         "${MINGW_PACKAGE_PREFIX}-spice-protocol"
         "${MINGW_PACKAGE_PREFIX}-usbredir"
         "${MINGW_PACKAGE_PREFIX}-vala")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('strip' 'staticlibs')
license=("GPL 2")
url="https://www.spice-space.org/"
source=(https://www.spice-space.org/download/gtk/${_realname}-${pkgver}.tar.xz{,.sig}
        001-win.patch)
sha256sums=('5ae974731baf2b41316d4f0b3ae0c2e47f00bff91a5a617e189cd3dedcd96d8e'
            'SKIP'
            '8bb6f1896df080746736a74200f094bae4f48ac766d46a1793a761728fb01202')
validpgpkeys=('206D3B352F566F3B0E6572E997D9123DE37A484F')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dintrospection=enabled \
    -Dsasl=enabled \
    -Dusbredir=enabled \
    -Dwebdav=enabled \
    -Dintrospection=enabled \
    -Dgtk_doc=enabled \
    -Dvapi=enabled \
    -Dcelt051=disabled \
    -Dopus=enabled \
    -Dsmartcard=disabled \
    -Dgtk=enabled \
    -Dlz4=enabled \
    -Dspice-common:manual=false \
    "../${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ninja install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
